﻿using System;
using RuntimeGizmos;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace SizeboxUI
{
	// Token: 0x020003C3 RID: 963
	public class TransformView : MonoBehaviour
	{
		// Token: 0x06001A5F RID: 6751 RVA: 0x000A4DB8 File Offset: 0x000A2FB8
		private void Awake()
		{
			this.control = Camera.main.GetComponent<InterfaceControl>();
			this.gizmo = Camera.main.GetComponent<TransformGizmo>();
			this.UpdateScaleText(1f);
			this.translateToolButton.onClick.AddListener(new UnityAction(this.OnTranslateClick));
			this.rotateToolButton.onClick.AddListener(new UnityAction(this.OnRotateClick));
			this.scaleToolButton.onClick.AddListener(new UnityAction(this.OnScaleClick));
			this.spaceButton.onClick.AddListener(new UnityAction(this.OnSpaceClick));
			this.sliderVerticalOffset.onValueChanged.AddListener(new UnityAction<float>(this.control.SetYAxisOffset));
			this.sliderRotX.onValueChanged.AddListener(new UnityAction<float>(this.control.RotateXAxis));
			this.sliderRotY.onValueChanged.AddListener(new UnityAction<float>(this.control.RotateYAxis));
			this.sliderRotZ.onValueChanged.AddListener(new UnityAction<float>(this.control.RotateZAxis));
			this.sliderScale.maxValue = Mathf.Log10(GameController.maxSize) * 100f;
			this.sliderScale.onValueChanged.AddListener(new UnityAction<float>(this.OnScaleChanged));
			this.control.OnSelected += this.OnChangedObject;
			this.toggleRotation.onValueChanged.AddListener(delegate(bool val)
			{
				this.control.LockRotation(val);
			});
			this.hideHandlesToggle.isOn = EditPlacement.showHandles;
			this.hideHandlesToggle.onValueChanged.AddListener(delegate(bool val)
			{
				this.ShowHandles(val);
			});
		}

		// Token: 0x06001A60 RID: 6752 RVA: 0x000A4F7A File Offset: 0x000A317A
		private void OnTranslateClick()
		{
			this.gizmo.SetToolMode(TransformType.Move);
		}

		// Token: 0x06001A61 RID: 6753 RVA: 0x000A4F88 File Offset: 0x000A3188
		private void OnRotateClick()
		{
			this.gizmo.SetToolMode(TransformType.Rotate);
		}

		// Token: 0x06001A62 RID: 6754 RVA: 0x000A4F96 File Offset: 0x000A3196
		private void OnScaleClick()
		{
			this.gizmo.SetToolMode(TransformType.Scale);
		}

		// Token: 0x06001A63 RID: 6755 RVA: 0x000A4FA4 File Offset: 0x000A31A4
		private void OnSpaceClick()
		{
			this.gizmo.ToggleSpaceMode();
		}

		// Token: 0x06001A64 RID: 6756 RVA: 0x000A4FB1 File Offset: 0x000A31B1
		private void Update()
		{
			this.UpdateButtonDisplay();
			this.UpdateScale();
		}

		// Token: 0x06001A65 RID: 6757 RVA: 0x000A4FC0 File Offset: 0x000A31C0
		private void UpdateButtonDisplay()
		{
			if (this.gizmo.overrideSpace)
			{
				this.spaceButton.gameObject.SetActive(false);
			}
			else
			{
				this.spaceButton.gameObject.SetActive(true);
			}
			if (this.gizmo.allowScaling && this.gizmo.overrideSpace)
			{
				this.scaleToolButton.gameObject.SetActive(true);
			}
			else
			{
				this.scaleToolButton.gameObject.SetActive(false);
			}
		}

		// Token: 0x06001A66 RID: 6758 RVA: 0x000A504C File Offset: 0x000A324C
		private void UpdateScale()
		{
			if (this.control == null || this.control.selectedEntity == null)
			{
				return;
			}
			this.applyChanges = false;
			this.sliderScale.value = this.control.GetScale();
			this.applyChanges = true;
		}

		// Token: 0x06001A67 RID: 6759 RVA: 0x000A50A8 File Offset: 0x000A32A8
		private void OnScaleChanged(float scale)
		{
			if (this.control.selectedEntity == null)
			{
				return;
			}
			if (this.applyChanges)
			{
				this.control.SetScale(scale);
			}
			this.UpdateScaleText(this.control.selectedEntity.HeightMesh);
		}

		// Token: 0x06001A68 RID: 6760 RVA: 0x000A50F9 File Offset: 0x000A32F9
		private void UpdateScaleText(float scale)
		{
			this.scaleLabel.text = "Size: " + GameController.ConvertScaleToHumanReadable(scale);
		}

		// Token: 0x06001A69 RID: 6761 RVA: 0x000A5116 File Offset: 0x000A3316
		private void OnChangedObject()
		{
			if (base.gameObject.activeSelf)
			{
				this.ReloadValues();
			}
		}

		// Token: 0x06001A6A RID: 6762 RVA: 0x000A512E File Offset: 0x000A332E
		private void OnEnable()
		{
			this.ReloadValues();
		}

		// Token: 0x06001A6B RID: 6763 RVA: 0x000A5138 File Offset: 0x000A3338
		private void ReloadValues()
		{
			if (this.control == null || this.control.selectedEntity == null)
			{
				return;
			}
			this.applyChanges = false;
			this.sliderVerticalOffset.value = this.control.GetYAxisOffset();
			this.sliderRotX.value = this.control.GetXRotation();
			this.sliderRotY.value = this.control.GetYRotation();
			this.sliderRotZ.value = this.control.GetZRotation();
			this.applyChanges = true;
			this.UpdateScaleText(this.control.selectedEntity.HeightMesh);
		}

		// Token: 0x06001A6C RID: 6764 RVA: 0x000A51E9 File Offset: 0x000A33E9
		private void ShowHandles(bool show)
		{
			EditPlacement.showHandles = show;
		}

		// Token: 0x04001C2A RID: 7210
		[SerializeField]
		[Header("Sliders")]
		private Slider sliderVerticalOffset;

		// Token: 0x04001C2B RID: 7211
		[SerializeField]
		private Slider sliderRotX;

		// Token: 0x04001C2C RID: 7212
		[SerializeField]
		private Slider sliderRotY;

		// Token: 0x04001C2D RID: 7213
		[SerializeField]
		private Slider sliderRotZ;

		// Token: 0x04001C2E RID: 7214
		[SerializeField]
		private Slider sliderScale;

		// Token: 0x04001C2F RID: 7215
		[SerializeField]
		[Header("Buttons")]
		private Button translateToolButton;

		// Token: 0x04001C30 RID: 7216
		[SerializeField]
		private Button rotateToolButton;

		// Token: 0x04001C31 RID: 7217
		[SerializeField]
		private Button scaleToolButton;

		// Token: 0x04001C32 RID: 7218
		[SerializeField]
		private Button spaceButton;

		// Token: 0x04001C33 RID: 7219
		[Header("Toggles")]
		[SerializeField]
		private Toggle toggleRotation;

		// Token: 0x04001C34 RID: 7220
		[SerializeField]
		private Toggle hideHandlesToggle;

		// Token: 0x04001C35 RID: 7221
		[SerializeField]
		[Header("Text")]
		private Text scaleLabel;

		// Token: 0x04001C36 RID: 7222
		private const string SCALE_STRING = "Size: ";

		// Token: 0x04001C37 RID: 7223
		private bool applyChanges;

		// Token: 0x04001C38 RID: 7224
		private InterfaceControl control;

		// Token: 0x04001C39 RID: 7225
		private TransformGizmo gizmo;
	}
}
